<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>修改密码</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="../js/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../style/admin.css" media="all"/>
    <link rel="stylesheet" href="../style/home.css" media="all"/>
</head>
<body layadmin-themealias="default">
<div class="" style="padding: 20px">
    <div class="layui-row layui-col-space15">
        <div class="layui-card pr20">
            <form class="layui-form" action="" id="postData">
                <div class="layui-form-item">
                    <label class="layui-form-label">原密码</label>
                    <div class="layui-input-block">
                        <input
                                type="password"
                                name="oldPwd"
                                required
                                lay-verify="required"
                                placeholder="请输入原密码"
                                autocomplete="off"
                                class="layui-input"
                        />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input
                                type="password"
                                name="newPwd"
                                required
                                lay-verify="required|newPwd"
                                placeholder="请输入新密码"
                                autocomplete="off"
                                class="layui-input"
                        />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确定新密码</label>
                    <div class="layui-input-block">
                        <input
                                type="password"
                                name="enterPwd"
                                required
                                lay-verify="required|enterPwd"
                                placeholder="请再次输入新密码"
                                autocomplete="off"
                                class="layui-input"
                        />
                    </div>
                </div>
                <button
                        type="submit"
                        class="layui-btn"
                        lay-submit=""
                        lay-filter="postData"
                        id="postBut"
                        style="display: none"
                >
                    立即提交
                </button>
            </form>
        </div>
    </div>
</div>
</body>
<script src="../js/layui/layui.js"></script>
<script src="../js/layui/config.js"></script>
<script>
    var callBackReturn = false,
        OnPost = false;

    var index = parent.layer.getFrameIndex(window.name);
    layui.config({
        base: '../js/lib/' //静态资源所在路径
    }).use(['form', 'CryptoJS'], function () {
        var form = layui.form,
            $ = layui.$;
        var CryptoJS = layui.CryptoJS;

        form.verify({
            newPwd: [/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,20}$/, '密码中必须包含字母、数字、特殊字符，长度大8到20位，且不能出现空格'],
            enterPwd: function (value) {
                if ($('input[name=newPwd]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });
        form.on('submit(postData)', function (obj) {
            var data = obj.field;
            data["oldPwd"] = CryptoJS.MD5(PM_CHECK_CODE + CryptoJS.MD5(data["oldPwd"]).toString()).toString();
            data["newPwd"] = CryptoJS.MD5(PM_CHECK_CODE + CryptoJS.MD5(data["newPwd"]).toString()).toString();
            data['enterPwd'] = "";
            $.ajax({
                url: '../account/setNewPassword', //url
                dataType: 'json', //数据格式
                type: 'POST', //请求方式
                async: false, //是否异步请求
                data: data,
                success: function (result) {
                    if (result.code === 0) {
                        top.parent.layer.msg(result.message, {icon: 1});
                        callBackReturn = true;
                        parent.layer.close(index);
                    } else {
                        top.layer.alert(result.message, {icon: 2});
                    }
                },
            });
            return false;
        });
    });

    function Buttun_Submit() {
        document.getElementById('postBut').click();
        return callBackReturn;
    }
</script>

</html>